package com.yang.singleton.hungry;

import java.io.Serializable;

/**
 * 饿汉式
 * @author yang
 * @version 0.1
 * @date 2019/4/12
 */
public class HungrySingleton implements Serializable {

    private static final HungrySingleton hungrySingleton = new HungrySingleton();

    private HungrySingleton() {
        if (null != hungrySingleton) {
            throw new RuntimeException("单例模式不能重复初始化");
        }
    }

    public static HungrySingleton getInstance() {
        return hungrySingleton;
    }

    public Object readResolve() {
        return hungrySingleton;
    }
}
